﻿//-----------------------------------------------------------------
//
// @(#)$Id: UnSendCountryDetails.aspx.cs,v 1.0 2013/12/13 17:53:10 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:53:10 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_BasTableAdapters;
using ebay.Dal.CenterDB_EbayTableAdapters;

public partial class UI_Bas_UnSendCountryDetails : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);     
        T_EbayCountryTableAdapter countryAdapter = new T_EbayCountryTableAdapter();
        ddlCountryName.DataSource = countryAdapter.GetData();
        ddlCountryName.DataTextField = "CountryName";
        ddlCountryName.DataBind();
    }
    static string act = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {          
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                switch (act)
                {
                    case "I":
                        break;
                    case "U":
                        this.txtUnSendId.Attributes["readonly"] = "readonly";
                        int unSendId = int.Parse(Request.QueryString["id"]);
                        T_EbayUnSendCountryTableAdapter ebayAdapter = new T_EbayUnSendCountryTableAdapter();
                        DataTable dt = ebayAdapter.GetDataByUnSendId(unSendId);                    
                        DataRow r = dt.Rows[0];
                        txtUnSendId.Value = r["UnSendId"].ToString();
                        ddlCountryName.Text = r["CountryName"].ToString();                                         
                        break;
                }
            }

        }
    }  

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }       
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                        T_EbayUnSendCountryTableAdapter ebayAdapter = new T_EbayUnSendCountryTableAdapter();
                        int flag = (int)ebayAdapter.IsExists(int.Parse(txtUnSendId.Value));
                        if (flag == 0)
                        {
                            int val = ebayAdapter.Insert(
                                     int.Parse(txtUnSendId.Value),
                                     "",
                                     ddlCountryName.SelectedValue
                                     );
                            if (val > 0)
                            {
                                Response.Write("<script>alert('添加成功!');window.location.href='UnSendCountry.aspx'</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert('此编号已经存在!..');</script>");
                        }
                    }
                    break;
                case "U":
                    {
                        T_EbayUnSendCountryTableAdapter ebayAdapter = new T_EbayUnSendCountryTableAdapter();
                        int val = ebayAdapter.Update(
                                 "",
                                 ddlCountryName.SelectedValue,
                                 int.Parse(txtUnSendId.Value)
                                );
                        if (val > 0)
                        {
                            Response.Write("<script>alert('修改成功!');window.location.href='UnSendCountry.aspx'</script>");
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
